﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data;
using HF.WCF.DBService;
using HF.Framework.SqlDataContract;
using HF.Framework.DataClient;
namespace HF.WCF.IISDBServer
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“Service1”。
    public class IISDBService : IDataBaseService
    {
        private IDatabase _dataBase;
        public IISDBService()
        {
            _dataBase = new DataProvider();


        }
        public int ExecuteNonQuery(SqlDataItem sqlDataItem)
        {
            return _dataBase.ExecuteNonQuery(sqlDataItem);
        }

        public DataSet ExecuteQuery(SqlDataItem sqlDataItem)
        {

            return _dataBase.ExecuteQuery(sqlDataItem);
        }

        public bool ExecuteNonQueryArray(SqlDataItemArray arySqlDataItem)
        {
            return _dataBase.ExecuteNonQueryArray(arySqlDataItem);
        }

        public string ExecuteScalar(SqlDataItem sqlDataItem)
        {
            return _dataBase.ExecuteScalar(sqlDataItem);
        }

        public bool RecordExists(SqlDataItem sqlDataItem)
        {
            return _dataBase.RecordExists(sqlDataItem);
        }
        public string GetCurrentDatabaseName()
        {
            return _dataBase.GetCurrentDatabaseName();
        }
        public DataSet GetDBQuery(string databaseName)
        {
            return _dataBase.GetDBQuery(databaseName);
        }

        public DataSet GetDTColumnsQuery(string tableName, string databaseName)
        {
            return _dataBase.GetDTColumnsQuery(tableName, databaseName);
        }
        //public string GetSlXml(SqlDataItem sqlDataItem)
        //{
        //    DataSet ds= _dataBase.ExecuteQuery(sqlDataItem);
        //    return Connector.ToXml(ds);
        //}
        public string GetXml(SqlDataItem sqlDataItem)
        {
            DataSet ds = _dataBase.ExecuteQuery(sqlDataItem);
            return ds.GetXml();
        }
        #region 获得一个空结构
        public DataSet GetBlankDataSet(List<string> tableNames)
        {
            return GetBlankDataSet(tableNames, null);
        }
        public DataSet GetBlankDataSet(List<string> tableNames, string databaseName)
        {
            return _dataBase.GetBlankDataSet(tableNames, databaseName);
        }
        #endregion

        #region 更新数据集
        public void UpdateDataSetWithTranse(DataSet dataSet)
        {
            UpdateDataSetWithTranse(dataSet, null);
        }
        /// <summary>
        /// 更新数据集，启动数据库事务
        /// </summary>
        /// <param name="ds">数据集</param>
        /// <param name="databaseName">数据库名</param>
        public void UpdateDataSetWithTranse(DataSet dataSet, string databaseName)
        {
            _dataBase.UpdateDataSetWithTranse(dataSet, databaseName);
        }

        #endregion
    }
}
